#!/usr/bin/python
# -*-coding: UTF-8 -*-
"""
# Time: 2021/10/31 22:36
# @Author: 修养
# @Project_name: PROJECT_NAME
"""
student_0 = {'id': '0001', 'name': '李白'}
print('输出初始字典：', student_0)
print('输出name对应的值：', student_0['name'])
student_0['age'] = '100'
print('给字典添加键值对后的字典为：', student_0)
student_0['age'] = '290'
print('修改age对应的值：', student_0)
del student_0['age']
print('删除age键值对：', student_0)


print('~~~~~~~~~~~~~2、通过键得到值~~~~~~~~~~~~~~~')
student_1 = {'id': '0001', 'name': '李白', 'age': '100'}
name = student_1['name']
print('输出name对应的值：', name)
id = student_1.get('id')
print('输出id对应的值：', id)
student_1['age'] = '200'
print('修改age对应的值：', student_1)
print('删除末尾的键值对并返回：', student_1.popitem())
student_1.update({'gender': '男'})
print('更新字典：', student_1)
m = {'age': '300', 'hobby': '写诗', 'id': '1001'}
student_1.update(m)
print('更新后字典：', student_1)

print('~~~~~~~~~~~~~~3、遍历~~~~~~~~~~~~~~~~~~')
print('遍历所有键值对:')
for key, value in student_1.items():
    print('key:', key, 'value:', value, end='  ')
print()
print('遍历字典中所有的键：')
for key in student_1.keys():
    print('key:', key, end='  ')
print()
print('遍历字典中所有的值：')
for value in student_1.values():
    print('value:', value, end='   ')
print()